﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserConTrols_Khung_Loginl : System.Web.UI.UserControl
{
    DataProvider duLieu = new DataProvider();

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty((string)Session["Username"]) && (int)Session["Logged"] == 1)
            {
                Logged.Visible = true;
                Login.Visible = false;
                usernamelogged.Text = "<a href='Thong_Tin_Tai_Khoan.aspx' title='" + (string)Session["Username"] + "'>" + (((string)Session["Username"]).Length > 10 ? ((string)Session["Username"]).Substring(0, 9) + "..." : (string)Session["Username"]) + "</a>";
                tenkh.Text = "<a href='Thong_Tin_Tai_Khoan.aspx' title='" + (string)Session["TenKH"] + "'>" + (((string)Session["TenKH"]).Length > 20 ? ((string)Session["TenKH"]).Substring(0, 19) + "..." : (string)Session["TenKH"]) + "</a>";
            }
            else
            {
                Logged.Visible = false;
                Login.Visible = true;
            }
        }
    }

    protected void dangnhap_Click(object sender, System.EventArgs e)
    {
        string Username = UserNamez.Text;
        string Password = Passwordz.Text;
        if (!string.IsNullOrEmpty(Username) & !string.IsNullOrEmpty(Password))
        {
            if (duLieu.Check_Login(Username, Password) == true)
            {
                Session["Username"] = Username;
                Session["Logged"] = 1;
                Response.Redirect("Default.aspx");
            }
            else
            {
                dangnhapsai.Visible = true;
                Session["Username"] = "";
                Session["Logged"] = 0;
            }
        }
    }

    protected void thoat_Click(object sender, System.EventArgs e)
    {
        Session["Username"] = "";
        Session["Logged"] = 0;
        Session["TenKH"] = "";
        Session["ID"] = "";
        Response.Redirect("Default.aspx");
    }

    protected void dangky_Click(object sender, System.EventArgs e)
    {
        Response.Redirect("Dang_Ky_Thanh_Vien.aspx");
    }

    protected void phuchoipass_Click(object sender, System.EventArgs e)
    {
        Response.Redirect("Phuc_Hoi_Pass.aspx");
    }
}